import jwt from 'jsonwebtoken';

const signkey = 'mes_qdhd_mobile_xhykjyxgs';

export const setToken = (username, password) => {
	return new Promise((resolve, reject) => {
		const token = jwt.sign({
			name: username,
			pw: password
		}, signkey, { algorithm: 'HS256', expiresIn: '24h' });
		resolve('Bearer ' + token);
	})
}

export const setMailToken = (username, email) => {
	return new Promise((resolve, reject) => {
		const token = jwt.sign({
			name: username,
			email: email
		}, signkey, { algorithm: 'HS256', expiresIn: '0.25h' });
		resolve('Bearer ' + token);
	})
}

export const verToken = (token) => {
	return new Promise((resolve, reject) => {
		var info = jwt.verify(token.split(' ')[1], signkey, { algorithms: ['HS256'] });
		resolve(info);
	})
}